import type { RouteRecordNormalized } from 'vue-router';
// import { appRoutes as mcRoutes } from '@mc/router/routes';

// import { DEFAULT_LAYOUT } from './base';
// import { IRoutePermission, menus } from './menus';
// import { AppRouteRecordRaw } from './types';

const modules = import.meta.glob('./modules/*.ts', { eager: true });
const externalModules = import.meta.glob('./externalModules/*.ts', {
  eager: true,
});

function formatModules(_modules: any, result: RouteRecordNormalized[]) {
  Object.keys(_modules).forEach((key) => {
    const defaultModule = _modules[key].default;
    if (!defaultModule) return;
    const moduleList = Array.isArray(defaultModule)
      ? [...defaultModule]
      : [defaultModule];
    // result.push(...moduleList);
    result = [...moduleList, ...result];
  });
  return result;
}

// const pageModules = import.meta.glob('../../views/**/*.vue');

// function loadPage(url: string): string {
//   /* @vite-ignore */
//   return `../../views/${url}.vue`;
// }

// function formatJson(data: IRoutePermission[]): AppRouteRecordRaw[] {
//   const routes: AppRouteRecordRaw[] = [];

//   data.forEach((e) => {
//     const children = e.children ? formatJson(e.children) : undefined;

//     routes.push({
//       path: e.path,
//       name: e.name,
//       component: e.location
//         ? pageModules[loadPage(e.location)]
//         : DEFAULT_LAYOUT,
//       meta: {
//         locale: e.locale,
//         requiresAuth: !!e.requiresAuth,
//         roles: e.roles,
//         icon: e.icon,
//       },
//       children,
//     });
//   });

//   return routes;
// }

// ...mcRoutes,
export const appRoutes: RouteRecordNormalized[] = formatModules(modules, []);

export const remoteRoutes = [];

export const appExternalRoutes: RouteRecordNormalized[] = formatModules(
  externalModules,
  []
);
